package com.company.cloud.page.modules.mgr.controller;

import com.company.cloud.common.auth.annotation.Authc;
import com.company.cloud.common.bean.BaseResult;
import com.company.cloud.common.bean.LoginSimpleUserInfo;
import com.company.cloud.common.utils.AuthContextUtils;
import com.company.cloud.page.modules.cache.models.WebPageComponentConfigModel;
import com.company.cloud.page.modules.mgr.controller.req.*;
import com.company.cloud.page.modules.mgr.service.WebPageComponentConfigMgrService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * WEB页面组件管理
 */
@Authc
@RestController
@RequestMapping("/mgr/cms/webPageComponent")
@Api(tags = "Page_MGR_WEB页面组件管理")
public class WebPageComponentConfigMgrController {

    @Autowired
    private WebPageComponentConfigMgrService webPageComponentConfigMgrService;

    @PostMapping("/list")
    @ApiOperation(value="列表", response= WebPageComponentConfigModel.class)
    public BaseResult list(@RequestBody WebPageComponentConfigListParam params) {
        LoginSimpleUserInfo userInfo=AuthContextUtils.getUser();
        List<WebPageComponentConfigModel> data= webPageComponentConfigMgrService.list(params,userInfo);
        return BaseResult.ok(data);
    }

    @PostMapping("/add")
    @ApiOperation(value="新增", response= BaseResult.class)
    public BaseResult add(@RequestBody WebPageComponentConfigAdd2EditParam params) {
        LoginSimpleUserInfo userInfo=AuthContextUtils.getUser();
        webPageComponentConfigMgrService.save(params,userInfo);
        return BaseResult.ok();
    }

    @PostMapping("/edit")
    @ApiOperation(value="修改", response= BaseResult.class)
    public BaseResult edit(@RequestBody WebPageComponentConfigAdd2EditParam params) {
        LoginSimpleUserInfo userInfo=AuthContextUtils.getUser();
        webPageComponentConfigMgrService.update(params,userInfo);
        return BaseResult.ok();
    }


    @GetMapping("/info")
    @ApiOperation(value="查看", response= WebPageComponentConfigModel.class)
    public BaseResult info(@RequestParam("code")String code) {
        WebPageComponentConfigModel data= webPageComponentConfigMgrService.info(code);
        return BaseResult.ok(data);
    }


    @GetMapping("/del")
    @ApiOperation(value="删除", response= BaseResult.class)
    public BaseResult del(@RequestParam("code")String code) {
        LoginSimpleUserInfo userInfo=AuthContextUtils.getUser();
        webPageComponentConfigMgrService.del(code,userInfo);
        return BaseResult.ok();
    }


    @GetMapping("/updown")
    @ApiOperation(value="上下架", response= BaseResult.class)
    public BaseResult updown(@RequestBody WebPageComponentConfigUpDownParam params) {
        LoginSimpleUserInfo userInfo=AuthContextUtils.getUser();
        webPageComponentConfigMgrService.updown(params,userInfo);
        return BaseResult.ok();
    }











}
